
#include "stdint.h"


static char buf[] =
{
0x2B, 0x4D, 0x53, 0x55, 0x42, 0x3A, 0x20, 0x22, 0x64, 0x77, 0x71, 0x2F, 0x73, 0x2F, 0x38, 0x36, 0x37, 0x31, 0x38, 0x31, 0x30, 0x35, 0x30, 0x32,
0x30, 0x33, 0x39, 0x36, 0x37, 0x2F, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x6E, 0x66, 0x6F,
0x22, 0x2C, 0x33, 0x38, 0x20, 0x62, 0x79, 0x74,  0x65, 0x73, 0x2C, 0x22, 0x7B, 0x22, 0x6D, 0x73,
0x67, 0x49, 0x64, 0x22, 0x3A, 0x22, 0x31, 0x32, 0x34, 0x35, 0x36, 0x37, 0x38, 0x22, 0x2C, 0x22,
0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x3A,  0x22, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x7D, 0x22, 0x0D, 0x0A };

static char buf2[] =
{
	
	0x00,0x00,0x00,0x00,0x00,0x02,0x0D,0x0A,0xEE,0x5D,0x00,0x00,0xF0,0x1B,0x00,0x20,0x49,0x02,0x00,0x08,0x6F,0x02,0x00,0x08,0x71,
	0x02,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x73,0x02,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x75,0x02,0x00,0x08,0x01,0x4F,0x00,
	0x08,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,
	0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x00,0x00,0x00,0x00,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x79,
	0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x79,0x02,0x00,0x08,0x00,0x00,0x00,0x00,0x75,0x4F,0x00,0x08,0xA5,0x4F,0x00,0x08,0x79,0x02,0x00,0x08,0x00,0x00,0x00,
	0x00,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,0x21,0x51,0x00,0x08,0xE9,0x51,0x00,0x08,0x79,0x02,0x00,0x08,0x79,0x02,0x00,0x08,
	0x79,0x02,0x00,0x08,0x00,0xF0,0x02,0xF8,0x00,0xF0,0x95,0xF8,0x0C,0xA0,0x30,0xC8,0x08,0x38,0x24,0x18,0x2D,0x18,0xA2,0x46,0x67,
	0x1E,0xAB,0x46,0x54,0x46,0x5D,0x46,0xAC,0x42,0x01,0xD1,0x00,0xF0,0x87,0xF8,0x7E,0x46,0x0F,0x3E,0x0F,0xCC,0xB6,0x46,0x01,0x26,
	0x33,0x42,0x00,0xD0,0xFB,0x1A,0xA2,0x46,0xAB,0x46,0x33,0x43,0x18,0x47,0x90,0x6D,0x00,0x00,0xB0,0x6D,0x00,0x00,0x10,0x3A,0x02,
	0xD3,0x78,0xC8,0x78,0xC1,0xFA,0xD8,0x52,0x07,0x01,0xD3,0x30,0xC8,0x30,0xC1,0x01,0xD5,0x04,0x68,0x0C,0x60,0x70,0x47,0x00,0x00,
	0x00,0x23,0x00,0x24,0x00,0x25,0x00,0x26,0x10,0x3A,0x01,0xD3,0x78,0xC1,0xFB,0xD8,0x52,0x07,0x00,0xD3,0x30,0xC1,0x00,0xD5,0x0B,
	0x60,0x70,0x47,0x10,0xB5,0x6E,0x29,0x02,0xD1,0x00,0xF0,0x6F,0xF9,0x10,0xBD,0x70,0x29,0x02,0xD1,0x00,0xF0,0x8B,0xFA,0x10,0xBD,
	0x66,0x29,0x02,0xD1,0x06,0xF0,0xEB,0xFA,0x10,0xBD,0x03,0x68,0x1B,0x0A,0x01,0xD3,0x80,0x23,0x19,0x43,0x69,0x29,0x02,0xD1,0x00,
	0xF0,0x25,0xF9,0x10,0xBD,0x64,0x29,0x02,0xD1,0x00,0xF0,0x20,0xF9,0x10,0xBD,0x75,0x29,0x02,0xD1,0x00,0xF0,0x1B,0xF9,0x10,0xBD,
	0x6F,0x29,0x02,0xD1,0x00,0xF0,0x18,0xFA,0x10,0xBD,0x78,0x29,0x02,0xD1,0x00,0xF0,0x55,0xFA,0x10,0xBD,0xE4,0x29,0x02,0xD1,0x00,
	0xF0,0xB4,0xF9,0x10,0xBD,0x03,0x68,0xDB,0x09,0x01,0xD3,0x80,0x23,0x19,0x43,0x63,0x29,0x02,0xD1,0x01,0xF0,0x6C,0xFE,0x10,0xBD,
	0x73,0x29,0x02,0xD1,0x01,0xF0,0x6F,0xFE,0x10,0xBD,0xE3,0x29,0x02,0xD1,0x01,0xF0,0x79,0xFE,0x10,0xBD,0x00,0x20,0x10,0xBD,0x1F,
	0xB5,0x02,0xF0,0xD0,0xF9,0x04,0x00,0x00,0x20,0x00,0x21,0x06,0xF0,0x2D,0xFA,0x40,0x1C,0x60,0x60,0x00,0x20,0x00,0x21,0x06,0xF0,
	0x11,0xFA,0xE0,0x60,0x1F,0xBD,0x10,0xB5,0x10,0xBD,0x02,0xF0,0x5B,0xFF,0x11,0x46,0xFF,0xF7,0xE9,0xFF,0x05,0xF0,0xBA,0xFE
};


int CheckMessage(char* p, char* rTopic, char** payload, uint16_t length)
{
	char* pf;
	char* ps = NULL;
	char* ps2=NULL;
	int payload_length = -1;
	uint8_t topiclength=0;
	char* buff;
	buff = malloc(10);
	pf = strstr(p, "+MSUB:");
	if (pf != NULL)
	{
		ps = strstr(pf, "\"") + 1;
		if (ps != NULL)
		{
			ps2 = strstr(ps + 1, "\"") + 1;
			topiclength = ps2 - ps - 1;
		}
		if (topiclength > 0)
		{
			memcpy(rTopic, ps, topiclength);
			rTopic[topiclength] = 0;
			//			Log_d("topic:%s",rTopic);
			ps = strstr(ps2, ",") + 1;
			if (ps != NULL)
			{
				ps2 = strstr(ps + 1, ",") + 1;
				if (ps2 != NULL)
				{
					topiclength = ps2 - ps - 1;
				}
				if (topiclength < 10 && topiclength > 0)
				{
					memset(buff, 0, 10);
					memcpy(buff, ps, topiclength);

					payload_length = atoi(buff);

					*payload = ps2 + 1;
				}
			}
		}
	}

	if (buff)
	{
		free(buff);
	}
	return payload_length;
}

void main()
{
	char topic[128] = { 0 };
	char* payload=NULL;
	uint16_t length;
	printf("%s", buf2);
	length=CheckMessage(buf2, topic, &payload, sizeof(buf2));
	printf("length %d\r\n", length);

	printf("buff:%s", payload);


}